﻿#region Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.

// ==================================================================================================
// Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME	:   iConnect.Azure Application Framework
// COMPONENT ID :   NCS.IConnect.Azure.Diagnostics.AzureStorage.AzureStorageCloudPageBlob
// COMPONENT DESC:  	
//
// CREATED DATE/BY:  08 June 2012 / Lu Ya Ming
//
// REVISION HISTORY:	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

#endregion

using System;

using Microsoft.WindowsAzure.StorageClient;

namespace NCS.IConnect.Cloud.Core.AzureStorage
{
    /// <summary>
    /// The Azure storage cloud page blob.
    /// </summary>
    public class AzureStorageCloudPageBlob : ICloudPageBlob
    {
        private readonly CloudPageBlob pageBlob;
        private readonly ICloudBlobClient serviceClient;
        private readonly ICloudBlobContainer container;

        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageCloudPageBlob"/> class.
        /// </summary>
        /// <param name="pageBlob">The page BLOB.</param>
        /// <exception cref="System.ArgumentNullException">pageBlob</exception>
        public AzureStorageCloudPageBlob(CloudPageBlob pageBlob)
        {
            if (pageBlob == null)
            {
                throw new ArgumentNullException("pageBlob");
            }

            this.pageBlob = pageBlob;
            this.serviceClient = new AzureStorageCloudBlobClient(this.pageBlob.ServiceClient);
            this.container = new AzureStorageCloudBlobContainer(this.pageBlob.Container);
        }

        /// <summary>
        /// Gets the service client.
        /// </summary>
        /// <value>
        /// The service client.
        /// </value>
        public ICloudBlobClient ServiceClient
        {
            get { return this.serviceClient; }
        }

        /// <summary>
        /// Gets the container.
        /// </summary>
        /// <value>
        /// The container.
        /// </value>
        public ICloudBlobContainer Container
        {
            get { return this.container; }
        }

        /// <summary>
        /// Gets the URI.
        /// </summary>
        /// <value>
        /// The URI.
        /// </value>
        public Uri Uri
        {
            get { return this.pageBlob.Uri; }
        }

        /// <summary>
        /// Creates the specified size.
        /// </summary>
        /// <param name="size">The size.</param>
        public void Create(long size)
        {
            this.pageBlob.Create(size);
        }
    }
}
